const router = require('express').Router();

const { check, validationResult } = require('express-validator'); //数据验证

const courseControllers = require("../../controllers/courseControllers");

/* GET */
router.get(
    '/',
    [
      check('pageNo').notEmpty().withMessage('页码不能为空'),
      check('pageSize').notEmpty().withMessage('条数不能为空')
    ],
    async function (req, res, next) {
    
      const errors = validationResult(req)
      if (!errors.isEmpty()) {
        return res.sendResult(null, 400, errors.array()[0].msg);
      }
  
      let { id } = req.auth;

      let data = await courseControllers.selectListByStudentId(id,req.query.pageNo,req.query.pageSize);
  
      res.sendResult(data,200,"请求成功");
      
    });
  
  module.exports = router;

/* GET */
router.get(
  '/courses',
  [
    check('pageNo').notEmpty().withMessage('页码不能为空'),
    check('pageSize').notEmpty().withMessage('条数不能为空')
  ],
  async function (req, res, next) {
    
    const errors = validationResult(req)
    if (!errors.isEmpty()) {
      return res.sendResult(null, 400, errors.array()[0].msg);
    }

    let data = await courseControllers.selectListByChoose(req.query.pageNo,req.query.pageSize,req.query.cname,req.query.tname);

    res.sendResult(data,200,"请求成功");
    
  });

module.exports = router;
